﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using DSPL.DataAccess;
using DSPL.Contracts;

namespace DSPL.Services.Services
{
   public  class TransactionDataRetrieve
    {
       public DataTable GetQuotationTaxData(int quotationKey)
       {
           var readMasterData = DatabaseAccess.Instance;

           List<ColumnWithValue> whereList = new List<ColumnWithValue>();
           List<ColumnWithValue> columnList = new List<ColumnWithValue>();

           columnList.Add(new ColumnWithValue { ColumnName = "fTax.TaxCode" });
           columnList.Add(new ColumnWithValue { ColumnName = "fTax.TaxName" });
           columnList.Add(new ColumnWithValue { ColumnName = "fQuoTaxRg.TaxRegNo"});
           columnList.Add(new ColumnWithValue { ColumnName = "fQuoTaxRg.TaxRegNo As ChkTaxRegNo" });
         
           List<ColumnWithValue> joinList = new List<ColumnWithValue>();
           joinList.Add(new ColumnWithValue { FromTable = "fQuoTaxRg", ToTable = "fTax", FromColumn = "TaxPk", ToColumn = "TaxPk", JoinType = QJoinType.INNERJOIN, Comparison = QComparison.EQUALS });

           whereList.Add(new ColumnWithValue { ColumnName = "fQuoTaxRg.QuoPk", Comparison = QComparison.EQUALS, ColumnValue = quotationKey });
           var quotationTaxQuery = new Query { TableName = "fQuoTaxRg", QType = QueryType.SELECT, ColValues = columnList.ToArray(), WhereClause = whereList.ToArray(), JoinStructure = joinList.ToArray() };
           return readMasterData.ExcecuteSelect(quotationTaxQuery);
       }

       public DataTable GetSalesOrderTaxData(int orderKey)
       {
           var readMasterData = DatabaseAccess.Instance;

           List<ColumnWithValue> whereList = new List<ColumnWithValue>();
           List<ColumnWithValue> columnList = new List<ColumnWithValue>();

           columnList.Add(new ColumnWithValue { ColumnName = "fTax.TaxCode" });
           columnList.Add(new ColumnWithValue { ColumnName = "fTax.TaxName" });
           columnList.Add(new ColumnWithValue { ColumnName = "fOrdTaxRg.TaxRegNo" });
           columnList.Add(new ColumnWithValue { ColumnName = "fOrdTaxRg.TaxRegNo As ChkTaxRegNo" });

           List<ColumnWithValue> joinList = new List<ColumnWithValue>();
           joinList.Add(new ColumnWithValue { FromTable = "fOrdTaxRg", ToTable = "fTax", FromColumn = "TaxPk", ToColumn = "TaxPk", JoinType = QJoinType.INNERJOIN, Comparison = QComparison.EQUALS });

           whereList.Add(new ColumnWithValue { ColumnName = "fQuoTaxRg.QuoPk", Comparison = QComparison.EQUALS, ColumnValue = orderKey });
           var salesOrderTaxQuery = new Query { TableName = "fQuoTaxRg", QType = QueryType.SELECT, ColValues = columnList.ToArray(), WhereClause = whereList.ToArray(), JoinStructure = joinList.ToArray() };
           return readMasterData.ExcecuteSelect(salesOrderTaxQuery);
       }

       public DataTable GetInvoiceTaxData(int invoiceKey)
       {
           var readMasterData = DatabaseAccess.Instance;

           List<ColumnWithValue> whereList = new List<ColumnWithValue>();
           List<ColumnWithValue> columnList = new List<ColumnWithValue>();

           columnList.Add(new ColumnWithValue { ColumnName = "fTax.TaxCode" });
           columnList.Add(new ColumnWithValue { ColumnName = "fTax.TaxName" });
           columnList.Add(new ColumnWithValue { ColumnName = "fInvTaxRg.TaxRegNo" });
           columnList.Add(new ColumnWithValue { ColumnName = "fInvTaxRg.TaxRegNo As ChkTaxRegNo" });

           List<ColumnWithValue> joinList = new List<ColumnWithValue>();
           joinList.Add(new ColumnWithValue { FromTable = "fInvTaxRg", ToTable = "fTax", FromColumn = "TaxPk", ToColumn = "TaxPk", JoinType = QJoinType.INNERJOIN, Comparison = QComparison.EQUALS });

           whereList.Add(new ColumnWithValue { ColumnName = "fInvTaxRg.InvPk", Comparison = QComparison.EQUALS, ColumnValue = invoiceKey });
           var invoiceTaxQuery = new Query { TableName = "fInvTaxRg", QType = QueryType.SELECT, ColValues = columnList.ToArray(), WhereClause = whereList.ToArray(), JoinStructure = joinList.ToArray() };
           return readMasterData.ExcecuteSelect(invoiceTaxQuery);
       }
    }
}
